package com.zhongkai.web.control.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhongkai.model.code.TCsXtcs;
import com.zhongkai.model.config.User;
import com.zhongkai.model.declare.TSbCcsspxx;
import com.zhongkai.service.declare.SpCancelService;

@Controller
@RequestMapping(value="/system/ajax/zzzdSpCancel.do")
public class ZzzdspCancelAjaxControl {
	
	private SpCancelService spCancelService;
	
	@Resource
	public void setSpCancelService(SpCancelService spCancelService) {
		this.spCancelService = spCancelService;
	}
	
	

	/*根据税票号码检验,Ajax调用*/
	@RequestMapping(params="method=check")
	public String zzzdSpCancel(HttpServletResponse response,HttpServletRequest request,String dqsphm,String dqzb) throws IOException{
			PrintWriter out;
			try {
				out = response.getWriter();
				User user=(User)request.getSession().getAttribute("user");
				//取得当前登录用户的编号
				String identifier=user.getUserIdentifier();
				//根据当前用户编号取得系统参数
				TCsXtcs tCsXtcs=(TCsXtcs)spCancelService.getSingle(TCsXtcs.class, "csz", identifier);
				//取得当前票号的票税信息
				//TSbCcsspxx tSbCcsspxx=(TSbCcsspxx)spCancelService.getSingle(TSbCcsspxx.class, "sphm", sphm.trim());
				List<TSbCcsspxx> tSbCcsspxxList=(List<TSbCcsspxx>)spCancelService.select("from TSbCcsspxx where sphm=? and zb=? and pzzlDm=?", new Object[]{dqsphm,dqzb,"02"});
				TSbCcsspxx tSbCcsspxx=tSbCcsspxxList.get(0);
				if(tSbCcsspxx==null){
//					out.write("<script>alert('无税票信息!');</script>");
					out.write("无税票信息!");
					return null;
				}else if(!"02".equals(tSbCcsspxx.getPzztDm())){
//					out.write("<script>alert('该税票已作废或者为空白!');</script>");
					out.write("该税票已作废或者为空白!");
					return null;
				}else if(tSbCcsspxx.getDzpjh()==null||"".equals(tSbCcsspxx.getDzpjh())){
//					out.write("<script>if(confirm('非电子税票,您想转到作废税票界面进行作废?')){location.href='system/ticket/spCancelform.jsp';};</script>");
//					out.write("非电子税票，请转到作废税票界面进行作废!");
					out.write("notSpecific");
					return null;
				}else if(tSbCcsspxx.getJbXh()!=null){
//					out.write("<script>alert('此税票已结报,不能作废!');</script>");
					out.write("此税票已结报,不能作废!");
					return null;
				}else if(!tSbCcsspxx.getCzrDm().equals(identifier)&&!"0002".equals(tCsXtcs.getCsDm())){
//					out.write("<script>alert('您不能操作此税票!');</script>");
					out.write("您不能操作此税票!");
					return null;
				}else{
					out.write("ok");
					return null;
				}
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
			
	}
	
	
	
}
